package com.mego.tzadd.activitys;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.widget.TextView;

import com.mego.tzadd.R;
import com.mego.tzadd.database.manager.JtinfoCenter;

import zuo.biao.library.base.BaseTabActivity;
import zuo.biao.library.interfaces.OnBottomDragListener;

public class JtInfoTabActivity extends BaseTabActivity implements OnBottomDragListener {
    private final String TAG = "JtInfoTabActivity";

    /**
     * 启动这个Activity的Intent
     *
     * @param context
     * @return
     */
    public static Intent createIntent(Context context) {
        return new Intent(context, JtInfoTabActivity.class);
    }
    //启动方法>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    @Override
    public Activity getActivity() {
        return this;
    }

    @SuppressLint("MissingSuperCall")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState, this);

        setContentView(R.layout.jtinfo_tab_activity, this);

        if (JtinfoCenter.getInstance().jtdetailinfo == null) {
            showShortToast("錯誤的機臺！");
            finish();
        }

        //功能归类分区方法，必须调用<<<<<<<<<<
        initView();
        initData();
        initEvent();
        //功能归类分区方法，必须调用>>>>>>>>>>



    }

    @Override
    public void initView() {//必须在onCreate方法内调用
        super.initView();


    }

    @Override
    public void initData() {//必须在onCreate方法内调用
        super.initData();
    }

    @Override
    @Nullable
    public String getTitleName() {
        return JtinfoCenter.getInstance().jtdetailinfo.getName();
    }

    @Override
    @Nullable
    public String getReturnName() {
        return "";
    }

    @Override
    @Nullable
    public String getForwardName() {
        return "";
    }

    @Override
    protected String[] getTabNames() {
        return getResources().getStringArray(R.array.tab_jtinfo);
    }

    JtInfoFragment0 _jtInfoFragment0;
    JtInfoFragment1 _jtInfoFragment1;
    JtInfoFragment2 _jtInfoFragment2;

    @Override
    protected Fragment getFragment(int position) {
        //示例代码<<<<<<<<<<<<<<<<<<
        if (_jtInfoFragment0 == null) {
            _jtInfoFragment0 = JtInfoFragment0.createInstance();
        }
        if (_jtInfoFragment1 == null) {
            _jtInfoFragment1 = JtInfoFragment1.createInstance();
        }
        if (_jtInfoFragment2 == null) {
            _jtInfoFragment2 = JtInfoFragment2.createInstance();
        }

        Fragment fragment;
        switch (position) {
            case 1:
                fragment = _jtInfoFragment1;
                break;
            case 2: {
                fragment = _jtInfoFragment2;
                break;
            }
            default: {
                fragment = _jtInfoFragment0;
                break;
            }
        }
        Bundle bundle = fragment.getArguments();
        if (bundle == null) {
            bundle = new Bundle();
        }
        fragment.setArguments(bundle);
        //示例代码>>>>>>>>>>>>>>>>>>
        return fragment;
    }

    //Data数据区(存在数据获取或处理代码，但不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    //Event事件区(只要存在事件监听代码就是)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    @Override
    public void initEvent() {//必须在onCreate方法内调用
        super.initEvent();
        topTabView.setOnTabSelectedListener(this);//覆盖super.initEvent();内的相同代码
    }

    @Override
    public void onDragBottom(boolean rightToLeft) {
        //示例代码<<<<<<<<<<<<<<<<<<
        if (rightToLeft) {
            return;
        }
        finish();
        //示例代码>>>>>>>>>>>>>>>>>>
    }

    @Override
    public void onTabSelected(TextView tvTab, int position, int id) {
        super.onTabSelected(tvTab, position, id);
//        showShortToast("onTabSelected  position = " + position);
    }




}